<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Tag;
use App\Models\Product;
use App\Services\Compose;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class TagController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        /*$str = 'photo/7bcf88870fd5567f2fe5f2488d02683e.jpg';
        $size = str_replace('.','-50.',$str);
        dd($size);*/
        //app(Compose::class)->start();



        return Grid::make(new Tag(), function (Grid $grid) {
            $grid->model()->orderBy('sort','asc');

            $grid->column('name')->editable();
            $grid->column('status')->switch();
            $grid->column('sort')->orderable();
            $grid->column('created_at');

            $grid->quickSearch('name')->placeholder('搜索...');

            $grid->quickCreate(function (Grid\Tools\QuickCreate $create) {
                $create->text('name', '名称');
            });


            $grid->actions(function (Grid\Displayers\Actions $actions){
                $actions->quickEdit();
                $actions->disableEdit();
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Tag(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('status');
            $show->field('sort');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Tag(), function (Form $form) {

            $form->text('name');
            $form->radio('status')->options(['1'=>'正常','0'=>'關閉'])->default(1);


        });
    }
}
